using System.Reflection;

namespace ZeroSum.Extensions;

/// <summary>
///     Assembly的扩展
/// </summary>
public static class AssemblyExtensions
{
    /// <summary>
    ///     扫描获取所有实现了泛型接口的类
    /// </summary>
    /// <param name="assembly"></param>
    /// <param name="target"></param>
    /// <returns></returns>
    public static IEnumerable<Type> GetImplsByGenericInterface(this Assembly assembly, Type target)
    {
        return assembly.GetTypes()
            .Where(t => t.CanInstanced() && t.IsImplGenericInterface(target));
    }
}